﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhSystemBLL.orderData;
using dhDataAcess.baseBLL;
using baseSet.importExport;

namespace dhsystem.orderForm
{
    public partial class Frmcheck2 : Form
    {
        public Frmcheck2(BindingSource BindingSourceorderMaster, string _orderNo)
        {
            InitializeComponent();
            BindingSourceorderMasterAdd = BindingSourceorderMaster;
            orderNo = _orderNo;
        }
        string orderNo;
        BindingSource BindingSourceorderMasterAdd;
        orderDetailBLL orderDetail = new orderDetailBLL();
        private void Frmcheck2_Load(object sender, EventArgs e)
        {
            labelorderStatus.DataBindings.Add("text", BindingSourceorderMasterAdd, "orderStatus");
            labelorderNo.DataBindings.Add("text", BindingSourceorderMasterAdd, "orderNo");
            labelcustNum.DataBindings.Add("text", BindingSourceorderMasterAdd, "custNum");
            labelorderDate.DataBindings.Add("text", BindingSourceorderMasterAdd, "orderDate");
            labelreceiveDate.DataBindings.Add("text", BindingSourceorderMasterAdd, "receiveDate");
            labelcustPoNo.DataBindings.Add("text", BindingSourceorderMasterAdd, "custPoNo");
            labelbillNo.DataBindings.Add("text", BindingSourceorderMasterAdd, "billNo");
            labelorderMark.DataBindings.Add("text", BindingSourceorderMasterAdd, "orderMark");
            labeluserNum.DataBindings.Add("text", BindingSourceorderMasterAdd, "userNum");
            labelworkername.DataBindings.Add("text", BindingSourceorderMasterAdd, "workername");
            labelkjf.DataBindings.Add("text", BindingSourceorderMasterAdd, "kjf");
            labelscf.DataBindings.Add("text", BindingSourceorderMasterAdd, "scf");
            labelaccount.DataBindings.Add("text", BindingSourceorderMasterAdd, "account");
            labelparkMark.DataBindings.Add("text", BindingSourceorderMasterAdd, "parkMark");
            labelmark.DataBindings.Add("text", BindingSourceorderMasterAdd, "mark");
            bindingSourceorderDetail.DataSource = orderDetail.getorderDetailByorderNo(labelorderNo.Text);
            labeladdress.DataBindings.Add("text", BindingSourceorderMasterAdd, "address");
            labelupdate.DataBindings.Add("text", BindingSourceorderMasterAdd, "updateDate");
            dGridDetail.DataSource = bindingSourceorderDetail;
            DcolumnSet.colSet(moduleInfo.orderDetail, dGridDetail);
        }

        private void toolcheck_Click(object sender, EventArgs e)
        {
            try
            {
                if (basicSql.getOrderStatus(labelorderNo.Text) == "审核")
                {
                    MessageBox.Show("订单已审核，无需再次审核");
                }
                else
                {
                    DialogResult result = MessageBox.Show("是否审核订单！", "提示信息", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        basicSql.getorderStatusUpdate(labelorderNo.Text, "审核");
                        if (basicSql.getblStatus(labelorderNo.Text) == "新建")
                        {
                        basicSql.getblStatusUpdate(labelorderNo.Text, "审核");
                        }
                        //bindingSourorderMaster.DataSource = orderMaster.getorderMasterAllByorderNo (orderNo );
                        //dGridorderMaster.DataSource = bindingSourorderMaster;
                        //DcolumnSet.colSet(moduleInfo.orderMaster, dGridorderMaster);
                        //bindingSourceorderDetail.DataSource = orderDetail.getorderDetailByorderNo(orderNo);
                        //dGridorderDetail.DataSource = bindingSourceorderDetail;
                        //DcolumnSet.colSet(moduleInfo.orderDetail, dGridorderDetail);

                        MessageBox.Show("审核成功");
                        labelorderStatus.Text = "审核";
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void toolcheckquxiao_Click(object sender, EventArgs e)
        {
            try
            {
                if (basicSql.getOrderStatus(labelorderNo.Text) == "审核")
                {
                    DialogResult result = MessageBox.Show("是否反审订单！", "提示信息", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        basicSql.getorderStatusUpdate(labelorderNo.Text, "新建");
                        //bindingSourorderMaster.DataSource = orderMaster.getorderMasterAllByorderNo (orderNo );
                        //dGridorderMaster.DataSource = bindingSourorderMaster;
                        //DcolumnSet.colSet(moduleInfo.orderMaster, dGridorderMaster);
                        //bindingSourceorderDetail.DataSource = orderDetail.getorderDetailByorderNo(orderNo);
                        //dGridorderDetail.DataSource = bindingSourceorderDetail;
                        //DcolumnSet.colSet(moduleInfo.orderDetail, dGridorderDetail);

                        MessageBox.Show("反审成功");
                        labelorderStatus.Text = "新建";
                    }


                }
                else
                {
                    MessageBox.Show("订单未审核，不需要反审");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dGridDetail_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            baseSet.datGridSet.gridViesSet.setGridViewRowNum(e, dGridDetail);
        }
    }
}
